package com.ia.aistream.controller;

import com.ia.aistream.common.constant.Constants;
import com.ia.aistream.common.core.controller.BaseController;
import com.ia.aistream.common.core.domain.AjaxResult;
import com.ia.aistream.common.utils.StringUtils;
import com.ia.aistream.manager.authen.conf.TokenFrom;
import com.ia.aistream.manager.authen.token.UserLoginToken;
import com.ia.aistream.model.system.entity.SysUser;
import com.ia.aistream.model.system.vo.OpenLoginVo;
import com.ia.aistream.service.system.IOpenLoginService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 登录验证
 * 
 * @author ia
 */
@RestController
@RequestMapping("/authentication")
public class OpenLoginController extends BaseController
{
    @Autowired
    private IOpenLoginService openLoginService;
    @PostMapping("/login")
    @ResponseBody
    public AjaxResult ajaxLogin(@Validated @RequestBody OpenLoginVo loginVo)
    {
        return AjaxResult.success(openLoginService.login(new UserLoginToken(loginVo.getName(),loginVo.getPassword(), TokenFrom.WEB)));
    }

    @PostMapping("/login1")
    @ResponseBody
    public AjaxResult ajaxLogin1(@RequestAttribute(Constants.USER_ATTR_KEY)SysUser user)
    {
        return AjaxResult.success(user);
    }

}
